#[derive(serde::Serialize, serde::Deserialize)]
pub struct ApiResponse<T> {
    pub code: i32,
    pub msg: String,
    pub data: Option<T>,
}

impl<T> ApiResponse<T> {
    pub fn ok(msg: impl Into<String>, data: Option<T>) -> Self {
        ApiResponse {
            code: 1,
            msg: msg.into(),
            data,
        }
    }

    /// 失败返回，msg 默认可以传 "失败"
    pub fn fail(msg: impl Into<String>, data: Option<T>) -> Self {
        ApiResponse {
            code: 0,
            msg: msg.into(),
            data,
        }
    }
}
